package 作业;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class tickets {
		private ArrayList<String> list;
		public tickets() {}
		public String[] getcity() throws SQLException {//获取城市信息
			ArrayList<String> ans=Getdb.op.GetStart();
			int size=ans.size();
			return (String[])ans.toArray(new String[size]);

		}

		public String[] getendcity() throws SQLException {
			ArrayList<String> ans=Getdb.op.GetEnd();
			int size=ans.size();
			return (String[] )ans.toArray(new String[size]);
		}
		/*public String[] gett(int start,int end) {//获取两城市车票信息
			String []temp=new String[16];
			temp[0]=top;
			Random r=new Random();
			DateFormat df=new SimpleDateFormat("YYYY年MM月dd日");
			int value=Math.abs(end-start)*r.nextInt(10,100);
			for(int i=1;i<=15;i++) {
				temp[i]=df.format(new Date(System.currentTimeMillis()+86400000*(i-1)))+"         "+citys[start]+"         "+citys[end]+"         "+value+"￥         "+(r.nextBoolean()?"有票":"无票");
			}
			return temp;
		}*/
		public String[] gett(String start,String end,boolean type) throws SQLException {//获取两城市车票信息
			ArrayList<Struct_ticket> ans;
			ans=Getdb.op.finds(start,end);
			String[] ret=new String[ans.size()+1];
			ret[0]="起点"+"    "+"终点"+"    "+"价格"+"    "+"出发时间"+"        "+"余票数";
			for(int i=0;i<ans.size();i++){
				ret[i+1]=ans.get(i).start+"    "+ans.get(i).end+"    "+(type?0.8*ans.get(i).cost:ans.get(i).cost)+"    "+ans.get(i).time+"    "+ans.get(i).quantity;
			}
		return ret;
		}
}
